﻿/*                              
   Copyright 2011 Nils Kopal, Christopher Krüger, Simone Sauer, Dennis Nolte, Uni Duisburg-Essen

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Sharebert.SearchLibrary.Interfaces
{
    /// <summary>
    /// Clients network interface used by the client GUI to communicate with the server.
    /// Enables the client to send a list of files to offer and to perform a search request.
    /// </summary>
    public interface ISearchClient
    {

        /// <summary>
        /// Sends a list of files to the server, that this client wants to offer for download.
        /// </summary>
        /// <param name="files">A list of files to offer</param>
        /// <exception cref="Sharebert.SearchLibrary.SerializationException">Serialization of the offering files failed</exception>
        /// <exception cref="Sharebert.SearchLibrary.NetworkException">Error while sending the search results</exception>
        /// <exception cref="Sharebert.SearchLibrary.NetworkStreamException">Network stream is not writable</exception>
        void Offer(FileOffer[] files);

        /// <summary>
        /// Sends a search request to the server, requesting for files that match the given regular expression.
        /// </summary>
        /// <param name="regex">The regular expression, used for search</param>
        /// <exception cref="System.ArgumentException">Regex is null or whitespace</exception>
        /// <exception cref="Sharebert.SearchLibrary.HeaderException">The received server message has a malformed header</exception>
        /// <exception cref="Sharebert.SearchLibrary.NetworkException">Error while sending the search results</exception>
        /// <exception cref="Sharebert.SearchLibrary.NetworkStreamException">Network stream is not writable</exception>
        /// <exception cref="Sharebert.SearchLibrary.SerializationException">Serialization of the offering files failed</exception>
        void Search(String regex);

        /// <summary>
        /// The hostname or IP of the server.
        /// </summary>
        string ServerAddress { get; set; }

        /// <summary>
        /// The port of the server.
        /// </summary>
        int ServerPort { get; }

        /// <summary>
        /// Sending and receiving messages will timeout after the specified time in seconds.
        /// </summary>
        int Timeout { get; set; }

        /// <summary>
        /// The address used by the client to wait for file requests.
        /// </summary>
        string ListenAddress { get; set; }

        /// <summary>
        /// The port used by the client to wait for file requests.
        /// </summary>
        int ListenPort { get; set; }

        /// <summary>
        /// The server did not respond after Timeout seconds.
        /// </summary>
        event EventHandler<EventArgs> ConnectionLost;

        /// <summary>
        /// The server responds to a search request.
        /// </summary>
        event EventHandler<SearchResultEventArgs> SearchResultReceived;
    }


}
